package java3_9;

import java.util.Scanner;

//吃货联盟订餐系统
public class test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
         int menuNum = 0;
         int copies = 0;//菜品份数
        int qianshou  = 0;
        int Del = 0;
         int count = 0;
         int dianZan = 0;
        String [] name = {"张晴","张晴", null,"张三"};
        String [] orderCount ={"红烧带鱼两份","红烧带鱼两份","","时令鲜蔬一份"};
        String [] time = {"12","18","","17"};
        String [] address = {"天成路207号","天成路207号","","马鞍山路203号"};
        String [] state = {"已完成","已预定","","已完成"};
        String [] orderPrice = {"76.0","45.0","","30.0"};
        String [] menu = {"红烧带鱼","鱼香肉丝","时令鲜蔬"};
        String [] signFor = {"未签收","未签收","未签收","未签收"};
        double [] price = {38.0,20.0,10.0};
        int [] zan = {0,0,0};
        boolean y = true;
        int num = 0;
        String a = "";
        while (y){
            System.out.println("欢迎使用“吃货联盟订餐系统”");
            System.out.println("*****************************");
            System.out.println("1.我要订餐");
            System.out.println("2.查看餐袋");
            System.out.println("3.签收订单");
            System.out.println("4.删除订单");
            System.out.println("5.我要点赞");
            System.out.println("6.退出系统");
            System.out.println("*****************************");
            System.out.println("请选择：");
            num = scanner.nextInt();
            switch (num) {
                case 1: {
                    System.out.println("***我要订餐***");
                    System.out.println("请输入订餐人姓名：");
                    name[2] = scanner.next();
                    System.out.print("序号" + "\t" + "\t" + "菜名" + "\t" + "\t" + "单价" + "\t" + "\t" + "点赞数");
                    for (int i = 0; i < menu.length; i++) {
                        System.out.print((i + 1) + "\t" + "\t" + menu[i] + "\t" + "\t" + price[i] + "\t" + "\t" + zan[i]);
                    }
                    System.out.print("请选择您要点的菜品编号：");
                    menuNum = scanner.nextInt();
                    System.out.print("请选择您要点的份数");
                    copies = scanner.nextInt();
                    System.out.print("请输入送餐时间(送餐时间是10点至20点间整点送餐):");
                    time[2] = scanner.next();
                    System.out.print("请输入送餐地址：");
                    address[2] = scanner.next();
                    System.out.println("订餐成功！");
                    System.out.println("您订的是：" + menu[menuNum - 1] + copies + "份");
                    System.out.println("送餐时间是：" + address[2] + "点");
                    System.out.println("餐费：" + copies * price[menuNum - 1] + "元" + "," + "送餐费：0.0元" + "," + "总计："
                            + copies * price[menuNum - 1] + "元");
                    System.out.println("输入任意值返回");
                    a = scanner.next();
                    continue;
                }
                case 2: {
                    System.out.println("***查看餐袋***");
                    System.out.print("序号" + "\t" + "\t" + "\t" + "订单人" + "\t" + "\t" + "\t" + "餐品信息" + "\t" + "\t" + "\t" + "\t" + "送餐地址"
                            + "\t" + "\t" + "\t" + "\t" + "总金额" + "\t" + "\t" + "\t" + "送餐状态");
                    System.out.println();
                    for (int i = 0; i < name.length; i++) {
                        if (name[i] == null) {
                            continue;
                        } else {
                            System.out.println((i + 1) + "\t" + "\t" + "\t" + "\t" + name[i] + "\t" + "\t" + "\t" + orderCount[i]
                                    + "\t" + "\t" + "\t" + address[i] + "\t" + "\t" + "\t" + orderPrice[i] + "\t" + "\t" + "\t" + state[i] + "\n");
                            System.out.println();
                        }
                    }
                    System.out.println("输入任意值返回");
                    a = scanner.next();
                    continue;
                }
                case 3: {
                    System.out.println("***签收订单***");
                    System.out.println("请选择要签收的订单号：");
                    qianshou = scanner.nextInt();
                    while (true) {
                        if (qianshou>=name.length){
                            System.out.println("您输入的订单不存在：");
                            break;
                        }
                        for (int j = qianshou; j < name.length; j++) {
                            if (name[qianshou - 1] != null && state[qianshou - 1].equals("已预定")) {
                                System.out.println("订单签收成功！");
                                signFor[qianshou-1]="已签收";
                                break;
                            }
                            if (name[qianshou - 1] == null) {
                                System.out.println("订单不存在！");
                            }
                            System.out.println("订单已完成！");
                            break;
                        }
                        break;
                    }
                }

                        System.out.println("输入任意值返回");
                        a = scanner.next();
                        continue;

                case 4:{
                    System.out.println("***删除订单***");
                    System.out.println("请输入要删除的订单号：");
                    Del = scanner.nextInt();
                    Del = Del-1;

                        if (Del >= name.length||Del<0){
                            System.out.println("订单不存在！");
                            break;
                        }
                        for (int k = 0; k < name.length; k++) {
                            if (signFor[Del] == "未签收"){
                                System.out.println("您选择的订单未签收，不能删除！");
                                break;
                            }
                    }
                    for(int j= Del+1;j<name.length;j++){
                        name[j-1] = name[j];
                        orderCount[j-1] = orderCount[j];
                        time[j-1] = time[j];
                        address[j-1] = address[j];
                        state[j-1] = state[j];
                        orderPrice[j-1] = orderPrice[j];
                        signFor[j-1] = signFor[j];

                        name[name.length-1] = null;
                        orderCount[orderCount.length-1] = null;
                        time[time.length-1] = null;
                        address[address.length-1] = null;
                        state[state.length-1] = null;
                        orderPrice[orderPrice.length-1] = null;
                        signFor[signFor.length-1] = null;

                    }
                    System.out.println("输入任意值返回");
                    a = scanner.next();
                    continue;
                }
                case 5:{
                    System.out.println("***我要点赞***");
                    System.out.print("序号" + "\t" + "\t" + "菜名" + "\t" + "\t" + "单价" + "\t" + "\t" + "点赞数");
                    System.out.println();
                    for (int i = 0; i < menu.length; i++) {
                        System.out.print((i + 1) + "\t" + "\t" + menu[i] + "\t" + "\t" + price[i] + "\t" + "\t" + zan[i]);
                        System.out.println();
                    }
                    System.out.println("请选择您要点赞的菜品序号:");
                    dianZan = scanner.nextInt();
                    if (dianZan>=menu.length||dianZan<1){
                        System.out.println("您点赞的商品不存在！");
                        break;
                    }
                    zan[dianZan] = zan[dianZan]+1;
                    System.out.println("点赞成功！");
                    System.out.println("输入任意值返回");
                    a = scanner.next();
                    continue;
                }
                case 6:{
                    System.out.println("谢谢使用，欢迎下次光临！");
                    y = false;
                }
            }

        }

    }
}
